//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Resource Application Block
//===============================================================================

using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Management.Instrumentation;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Manageability;

namespace EntLibContrib.Resource.Configuration.Manageability
{
	/// <summary>
	/// Represents the configuration information from a
	/// <see cref="EntLibContrib.Resource.Configuration.DataResourceProviderData"/> instance.
	/// </summary>
	/// <seealso cref="EntLibContrib.Resource.Configuration.DataResourceProviderData"/>
	/// <seealso cref="ResourceProviderSetting"/>
	[ManagementEntity]
	public class DataResourceProviderSetting : ResourceProviderSetting
	{
		#region Fields
		private string databaseInstanceName;
		#endregion

		#region Properties
		/// <summary>
		/// Gets the name of the database instance for the represented configuration object.
		/// </summary>
		/// <value>The name of the database instance.</value>
		/// <seealso cref="EntLibContrib.Resource.Configuration.DataResourceProviderData.DatabaseInstanceName">DataResourceProviderData.DatabaseInstanceName</seealso>
		[ManagementProbe]
		public string DatabaseInstanceName
		{
			get { return databaseInstanceName; }
			set { databaseInstanceName = value; }
		}
		#endregion

		#region Construction
		/// <summary>
		/// Initializes a new instance of the <see cref="DataResourceProviderSetting"/> class.
		/// </summary>
		/// <param name="name">The name.</param>
		/// <param name="databaseInstanceName">Name of the database instance.</param>
		/// <param name="resourceBaseName">Name of the resource base.</param>
		public DataResourceProviderSetting(string name,
																			string databaseInstanceName,
																			string resourceBaseName)
			: base(name, resourceBaseName)
		{
			this.databaseInstanceName = databaseInstanceName;
		}
		#endregion

		#region Public Static Methods
		/// <summary>
		/// Returns an enumeration of the published <see cref="DataResourceProviderSetting"/> instances.
		/// </summary>
		/// <returns></returns>
		[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
		[ManagementEnumerator]
		public static IEnumerable<DataResourceProviderSetting> GetInstances()
		{
			return NamedConfigurationSetting.GetInstances<DataResourceProviderSetting>();
		}

		/// <summary>
		/// Returns the <see cref="DataResourceProviderSetting"/> instance corresponding to the provided values for the key properties.
		/// </summary>
		/// <param name="applicationName">Name of the application.</param>
		/// <param name="sectionName">Name of the section.</param>
		/// <param name="name">The name.</param>
		/// <returns>
		/// The published <see cref="DataResourceProviderSetting"/> instance specified by the values for the key properties,
		/// or <see langword="null"/> if no such an instance is currently published.
		/// </returns>
		[ManagementBind]
		public static DataResourceProviderSetting BindInstance(string applicationName,
																													 string sectionName,
																													 string name)
		{
			return NamedConfigurationSetting.BindInstance<DataResourceProviderSetting>(applicationName, sectionName, name);
		}
		#endregion
	}
}
